<template>
  <div class="login_container">
    <div class="login_box">
      <div class="login">
        <!-- 整体布局容器 -->
        <div class="center-wrapper">
          <!-- 头像区域 -->
          <div class="avatar_box">
            <img src="@/assets/logo.jpg" alt="" />
          </div>
          <el-form :model="form" ref="form" label-width="100px">
            <el-form-item label="用户名">
              <el-input v-model="form.username" />
            </el-form-item>
            <el-form-item label="密码">
              <el-input type="password" v-model="form.password" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleLogin">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { login, register } from '@/api/user';

export default {
  data() {
    return {
      form: {
        username: '',
        password: '',
      },
    };
  },
  methods: {
    async handleLogin() {
      try {
        console.log("132321")
        const response = await login(this.form);
        if (response.data == 1) {
          this.$message.error('登录失败,用户名或者密码错误');
          return;
        } else {
          this.$message.success('登录成功');
          this.$router.push('/employees');
        }
      } catch (error) {
        this.$message.error('登录失败');
      }
    },
  },
};
</script>

<style scoped>
.login_container {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url("../../assets/back.jpg") no-repeat center center fixed; /* 添加背景图片 */
  background-size: cover; /* 确保背景图片覆盖整个容器 */
}

.login_box {
  width: 350px;
  background-color: white;
  border-radius: 15px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); /* 添加阴影增加立体感 */
}

.login {
  padding: 30px;
}

.center-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar_box {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden; /* 确保图片超出部分隐藏，保持圆形 */
  margin-bottom: 30px; /* 增加头像和输入框之间的间距 */
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 给头像框添加阴影 */
}

.avatar_box img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 确保图片填满头像框 */
}

.el-form {
  width: 100%;
}

.el-form-item {
  margin-bottom: 20px; /* 增加输入框之间的间距 */
}

.el-input {
  width: 100%; /* 让输入框撑满表单宽度 */
}

.el-button {
  width: 100%; /* 让登录按钮撑满表单宽度 */
}
</style>
